package com.sws.controller;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.sws.Constant;
import com.sws.model.bean.B2SBannerPageBean;
import com.sws.model.bean.B2SNewsPageBean;
import com.sws.service.PushService;

@Controller
public class PushController {
	
	private Logger logger = LoggerFactory.getLogger(PushController.class);
	
	@Autowired
	private PushService service;

	@ResponseBody
	@RequestMapping("/t/getAllBanner")
	public String getAllBanner(B2SBannerPageBean bean) {
		logger.info("====> 获取所有轮播");
		JSONObject result = new JSONObject();
		try {
			result.put("status", Constant.INSTANSE.OK);
			result.put("data", service.getAllBanner(bean));
			result.put("msg", "获取所有轮播成功！");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			result.put("status", Constant.INSTANSE.SERVSER_ERROR);
			result.put("msg", "服务器内部错误！");
		}
		result.put("time", new Date());
		return result.toJSONString();
	}
	
	@ResponseBody
	@RequestMapping("/t/getAllNews")
	public String getAllNews(B2SNewsPageBean bean) {
		logger.info("====> 获取所有资讯");
		JSONObject result = new JSONObject();
		try {
			result.put("status", Constant.INSTANSE.OK);
			result.put("data", service.getAllNews(bean));
			result.put("msg", "获取所有资讯成功！");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			result.put("status", Constant.INSTANSE.SERVSER_ERROR);
			result.put("msg", "服务器内部错误！");
		}
		result.put("time", new Date());
		return result.toJSONString();
	}
}
